home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / GRAPH_FO / (GRAPH / CGRAPHTE / CGRAPHTA.C < prev    next >
Text File  |  1991-02-09  |  4KB  |  134 lines

  1. /******************************************************************************
  2.  CGraphTask.c
  3.  
  4.                             The GraphTask Class
  5.  
  6.     SUPERCLASS = CMouseTask.c
  7.  
  8.     Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
  9.  
  10.  ******************************************************************************/
  11.  
  12. #include <MacTypes.h>
  13. #include <Global.h>
  14. #include "CGraphTask.h"
  15.  
  16. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  17. /******************************************************************************
  18.     IGraphTask
  19.  
  20.         The IGraphTask should setup enough information to UNDO later.
  21. *******************************************************************************/
  22. void
  23. CGraphTask::IGraphTask(short aNameIndex, CPanorama *theRama, Graph *theGraph,
  24.         Point from) {
  25.  
  26.     itsStart = from;
  27.     itsGraph = theGraph;
  28.     itsRama = theRama;
  29.     IMouseTask(aNameIndex);
  30.     notified = false;    /* Notify only on succes !! */
  31.     }
  32.  
  33. /******************************************************************************
  34.     Notify
  35.         Notify its supervisor on succesful completion.
  36. *******************************************************************************/
  37. void
  38. CGraphTask::Notify() {
  39.     if(!notified) {
  40.         notified = true;
  41.         itsRama->Notify(this);
  42.         }
  43.     }
  44.  
  45. /******************************************************************************
  46.     BeginTracking
  47. *******************************************************************************/
  48. void
  49. CGraphTask::BeginTracking(Point *startPt) {
  50.     PenMode(patXor);
  51.     PenPat(gray);
  52.     Draw(itsStart, *startPt);
  53.     PenNormal();
  54.     }
  55.  
  56. /******************************************************************************
  57.     KeepTracking
  58. *******************************************************************************/
  59. void
  60. CGraphTask::KeepTracking(Point *currPt, Point *prevPt, Point *startPt) {
  61.     RgnHandle    clipRgn;
  62.     Rect        r, f;
  63.     long        curTicks;
  64.     Point        start, new;
  65.  
  66.     itsRama->GetPosition(&start);
  67.     clipRgn = NewRgn();
  68.     if( itsRama->AutoScroll(*currPt) || ! EqualPt(*currPt, *prevPt)) {
  69.         itsRama->GetPosition(&new);
  70.  
  71.         GetClip(clipRgn);
  72.         r = (**clipRgn).rgnBBox;
  73.         OffsetRect(&r, start.h - new.h, start.v - new.v);
  74.  
  75.         itsRama->GetFrame(&f);
  76.         PinInRect(&f, (Point *)&(r.top));
  77.         PinInRect(&f, (Point *)&(r.bottom));
  78.  
  79.         ClipRect(&r);    /* change clipping region to allow for scrolling */
  80.                         /* that may have occured */
  81.         PenMode(patXor);
  82.         PenPat(gray);
  83.         Draw(itsStart, *prevPt);
  84.  
  85.         SetClip(clipRgn);
  86.  
  87.         Draw(itsStart, *currPt);
  88.         PenNormal();
  89.         }
  90.     DisposeRgn(clipRgn);
  91.     }
  92.  
  93. void
  94. CGraphTask::EndTracking(Point *currPt, Point *prevPt, Point *startPt) {
  95.  
  96.         PenMode(patXor);
  97.         PenPat(gray);
  98.         Draw(itsStart, *prevPt);
  99.         PenNormal();
  100.  
  101.         itsStop = *currPt;
  102.     }
  103.  
  104. /******************************************************************************
  105.     Draw
  106.  
  107.         On entry the pattern is allready set to patXor. This method is called
  108.         alternately for drawing and erasing. Default draws a rect from a to b;
  109. *******************************************************************************/
  110. void
  111. CGraphTask::Draw(Point a, Point b) {
  112.     Rect    r;
  113.  
  114.     Pt2Rect(a, b, &r);
  115.     FrameRect(&r);
  116.     }
  117.  
  118. /******************************************************************************
  119.     GetStop
  120.         Return the last position.
  121. *******************************************************************************/
  122. void
  123. CGraphTask::GetStop(Point *pt) {
  124.     *pt = itsStop;
  125.     }
  126.  
  127. /******************************************************************************
  128.     GetRect
  129.         Return the rectangle that was spanned with the mouse move.
  130. *******************************************************************************/
  131. void
  132. CGraphTask::GetRect(Rect *result) {
  133.     Pt2Rect(itsStart, itsStop, result);
  134.     }